import numpy as np
import pandas as pd
def _ema(cls_se,n):
    a=1/n
    data =np.zeros(len(cls_se))
    for i in range(len(data)):
        if i==0:
            data[i]=cls_se[i]
        elif i<n:
            data[i]=(cls_se[i]+data[i-1])/2
        else:
            data[i]=a*cls_se[i]+(1-a)*data[i-1]#从首开始循环
            return data
data=pd.read_excel('data.xlsx')['Clsprc']
EMA=_ema(data,5)
print(EMA)